package me.hellp.helloworld.design.iterator;

/**
 * 具体容器角色(ConcreteAggregate)
 * 
 * @author linxm
 *
 */
public class MyConcreteAggregate implements MyAggregate {
	private Object[] list;
	private int size = 0;
	private int index = 0;

	public MyConcreteAggregate() {
		index = 0;
		size = 0;
		list = new Object[100];
	}

	@Override
	public void add(Object obj) {
		list[index++] = obj;
		size++;
	}

	@Override
	public MyIterator iterator() {

		return new MyConcreteIterator(this);
	}

	@Override
	public Object get(int index) {

		return list[index];
	}

	@Override
	public int getSize() {

		return size;
	}
}
